package com.dz.lm.web.controller.moneyBar;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.dz.lm.common.dto.MoneyBarDTO;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.common.util.FileUploadUtil;
import com.dz.lm.common.utils.json.JsonUtils;
import com.dz.lm.service.moneyBar.MoneyBarService;
import com.dz.lm.web.controller.BasicControl;


@RestController
@RequestMapping(value = "/rewriteUrl/moneyBar", produces = "application/json")
public class MoneyBarController extends BasicControl {
	
	@Autowired
    private MoneyBarService moneyBarService;
	
	/**
     * 查询地理位置信息列表
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/qryLocalList")
    public Map<String, Object> qryLocalList(HttpServletRequest request) throws ServiceException {
		List<Map<String, Object>> localLsit = moneyBarService.qryLocalList();
		JSONObject subjo = new JSONObject();
		subjo.put("localList", localLsit);
    	subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
		return parameterEncrypt(request, subjo);
    }
    
    @ResponseBody
    @RequestMapping("/homeMoneyBarList")
    public Map<String, Object> homeMoneyBarList(HttpServletRequest request) throws ServiceException {
    	String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = null;
    	//参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
		    	subjo.put("result", "01");
		    	subjo.put("message", "参数" + in + "异常");
		    	return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String position = param.get("position") != null? param.get("position").toString() : "";
		String size = param.get("size") != null? param.get("size").toString() : "";
		//province	省市编码
		String province = param.get("province") != null? param.get("province").toString() : "110000";
		//city	城市编码
		String city = param.get("city") != null? param.get("city").toString() : "";			
		//sortType	排序类型（0：吧员数量排序，1：距离最近+吧员数量排序）
		String sortType = param.get("sortType") != null? param.get("sortType").toString() : "";
		//productType	产品类型（01：凭信用，02：小抵押，03：车，04：房：05：极速贷，06：信用卡，07：POS专区，08：其他）
		String productType = param.get("productType") != null? param.get("productType").toString() : "";
		//state	0：待审核，1：审核拒绝，2：审核通过
		String state = param.get("state") != null? param.get("state").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position= "0";
		if ("".equals(size))
			size= "10";
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
		if (!"100000".equals(province)) {//全国：100000
			qryParam.put("province", province);
			//全北京 天津 上海 重庆
			if (!"".equals(city) && !"110100".equals(city) && !"120100".equals(city) && !"310100".equals(city) && !"500100".equals(city)) {
				qryParam.put("city", city);
			}
		}
		if (!"".equals(sortType)) {
			qryParam.put("sortType", sortType);
		}
		if (!"".equals(productType)) {
			qryParam.put("productType", productType);
		}
		if (!"".equals(state)) {
			qryParam.put("state", state);
		}
		Map<String, Object> retData = moneyBarService.homeMoneyBarList(qryParam);
		subjo = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
    	subjo.put("moneyBarList", retData.get("moneyBarList"));
		int count = (int) retData.get("count");
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
    	subjo.put("count", count);
    	subjo.put("page", page);
		return parameterEncrypt(request, subjo);
    }
	
	@ResponseBody
    @RequestMapping("/moneyBarSearch")
    public Map<String, Object> moneyBarSearch(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
    	//参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
		    	subjo.put("result", "01");
		    	subjo.put("message", "参数" + in + "异常");
		    	return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String position = param.get("position") != null? param.get("position").toString() : "";
		String size = param.get("size") != null? param.get("size").toString() : "";
		//province	省市编码
		String province = param.get("province") != null? param.get("province").toString() : "110000";
		//city	城市编码
		String city = param.get("city") != null? param.get("city").toString() : "";			
		//searchKey	搜索条件
		String searchKey = param.get("searchKey") != null? param.get("searchKey").toString() : "";
		//sortType	排序类型（0：吧员数量排序，1：距离最近+吧员数量排序）
		String sortType = param.get("sortType") != null? param.get("sortType").toString() : "";
		//productType	产品类型（01：凭信用，02：小抵押，03：车，04：房：05：极速贷，06：信用卡，07：POS专区，08：其他）
		String productType = param.get("productType") != null? param.get("productType").toString() : "";
		//state	0：待审核，1：审核拒绝，2：审核通过
		String state = param.get("state") != null? param.get("state").toString() : "2";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position= "0";
		if ("".equals(size))
			size= "10";
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
		if (!"100000".equals(province)) {//全国：100000
			qryParam.put("province", province);
			//全北京 天津 上海 重庆
			if (!"".equals(city) && !"110100".equals(city) && !"120100".equals(city) && !"310100".equals(city) && !"500100".equals(city)) {
				qryParam.put("city", city);
			}
		}
		if (!"".equals(searchKey.trim())){
			StringBuffer sb = new StringBuffer();
			searchKey = searchKey.trim();
			String key[] = searchKey.split(" ");
			for (String k : key) {
				sb.append(k);
				sb.append("%");
			}
			if (key != null && key.length > 0) {
				qryParam.put("searchKey", sb.substring(0, sb.length() - 1));
			}
		}
		if (!"".equals(sortType)) {
			qryParam.put("sortType", sortType);
		}
		if (!"".equals(productType)) {
			qryParam.put("productType", productType);
		}
		if (!"".equals(state)) {
			qryParam.put("state", state);
		}
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf(10));
		Map<String, Object> retData = moneyBarService.siftingSearch(qryParam);
		subjo = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
    	subjo.put("moneyBarList", retData.get("moneyBarList"));
		int count = (int) retData.get("count");
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
    	subjo.put("count", count);
    	subjo.put("page", page);
		return parameterEncrypt(request, subjo);
	}
	
	@ResponseBody
	@RequestMapping("/getMoneyBarDetail")
	public Map<String, Object> getMoneyBarDetail(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String barId = param.get("barId").toString();
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("barId", barId);
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
		qryParam.put("userId", request.getAttribute("userId"));
		Map<String, Object> retData = moneyBarService.qryMoneyBarDetail(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
//		subjo.put("moneyBar", retData.get("moneyBar"));
		subjo.put("productList", retData.get("productList"));
		subjo.put("productAgentCount", retData.get("productAgentCount"));
		subjo.put("barAgentCount", retData.get("barAgentCount"));
		int count = (int) retData.get("productCount");
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
	}

	@ResponseBody
	@RequestMapping("/addMoneyBar")
	@SuppressWarnings("unchecked")
	public Map<String, Object> addMoneyBar(HttpServletRequest request) throws ServiceException {
		Object imgUrl = request.getAttribute("imgUrl");
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		Map<String, Object> images = (Map<String, Object>) request.getAttribute("images");
    	Map<String, Object> urlMap = new HashMap<String, Object>();
    	if (images != null && !images.isEmpty()) {
    		urlMap = FileUploadUtil.uploadByInStream(images, imgUrl, "moneyBar");
    	}
    	Set<String> keys = urlMap.keySet();
		for (String key : keys) {
			 param.put(key, imgUrl + urlMap.get(key).toString());
		}
		int i = moneyBarService.addMoneyBar(param);
		JSONObject subjo = new JSONObject();
		if (i == 1) {
			subjo.put("result", "00");
			subjo.put("message", "创建成功");
		} else if (i == -1) {
			subjo.put("result", "01");
			subjo.put("message", "推荐码不存在，请重新输入！");
		} else {
			subjo.put("result", "02");
			subjo.put("message", "创建失败");
		}
		return parameterEncrypt(request, subjo);
	}
	
	
	@ResponseBody
	@RequestMapping("modifyMoneyBar")
	@SuppressWarnings("unchecked")
	public Map<String, Object> modifyMoneyBar(HttpServletRequest request) throws ServiceException {
		Object imgUrl = request.getAttribute("imgUrl");
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		Map<String, Object> images = (Map<String, Object>) request.getAttribute("images");
    	Map<String, Object> urlMap = new HashMap<String, Object>();
    	if (images != null && !images.isEmpty()) {
    		urlMap = FileUploadUtil.uploadByInStream(images, imgUrl, "moneyBar");
    	}
    	Set<String> keys = urlMap.keySet();
		for (String key : keys) {
			 param.put(key, imgUrl + urlMap.get(key).toString());
		}
		checkImage("licenseImage",param, 3);
		checkImage("authImage",param, 3);
		int i = moneyBarService.modifyMoneyBar(param);
		JSONObject subjo = new JSONObject();
		if (i == 1) {
			//物理删除用户操作删除的图片
			deleteImages(param.get("deleteFiles"));
			subjo.put("result", "00");
			subjo.put("message", "修改成功");
		} else {
			subjo.put("result", "-1");
			subjo.put("message", "修改失败");
		}
		return parameterEncrypt(request, subjo);
	}
	
	@ResponseBody
	@RequestMapping("getMoneyBarById")
	public Map<String, Object> getMoneyBarById(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		param.put("userId", request.getAttribute("userId"));
		MoneyBarDTO moneyBarDTO = moneyBarService.getMoneyBarById(param);
		JSONObject subjo = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
		subjo.put("moneyBarInfo", moneyBarDTO);
		return parameterEncrypt(request, subjo);
	}
	
	@ResponseBody
	@RequestMapping("qryMoneyBarListByUserId")
	public Map<String, Object> qryMoneyBarListByUserId(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
//		Map<String, Object> param = new HashMap<String, Object>();
//		param.put("createUserId", "2");
		List<MoneyBarDTO> moneyBarDtoList = moneyBarService.qryMoneyBarListByUserId(param);
		JSONObject subjo = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
		subjo.put("moneyBarList", moneyBarDtoList);
		return parameterEncrypt(request, subjo);
	}
	
	
	@ResponseBody
	@RequestMapping("/qryMoneyBarApplyProductList")
	public Map<String, Object> qryMoneyBarApplyProductList(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String barId = param.get("barId").toString();
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("barId", barId);
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("barId", 1);
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf("10"));
//		JSONObject subjo = new JSONObject();
		Map<String, Object> retData = moneyBarService.qryMoneyBarApplyProductList(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("applyProductList", retData.get("applyProductList"));
		int count = 10;
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
	}
	
	
	
	@ResponseBody
	@RequestMapping("/qryMoneyBarAgentList")
	public Map<String, Object> qryMoneyBarAgentList(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String barId = param.get("barId").toString();
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("barId", barId);
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("barId", 11);
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf("10"));
//		JSONObject subjo = new JSONObject();
		qryParam.put("qryState", "1");
		Map<String, Object> retData = moneyBarService.qryMoneyBarAgentList(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("nodeList", retData.get("nodeList"));
		int count = 10;
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
	}
	
	@ResponseBody
	@RequestMapping("/addMoneyBarFavorite")
	public Map<String, Object> addMoneyBarFavorite(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		param.put("userId", request.getAttribute("userId"));
//		Map<String, Object> param = new HashMap<String, Object>();
//		param.put("userId", "3");
//		param.put("barId", "1");
		int i = moneyBarService.addBarFavorite(param);
		JSONObject subjo = new JSONObject();
		if (i == 2) {
			subjo.put("result", "00");
			subjo.put("message", "您已成功入吧");
		} else if (i == 1) {
			subjo.put("result", "00");
			subjo.put("message", "加入成功");
		} else {
			subjo.put("result", "-1");
			subjo.put("message", "加入失败");
		}
		return parameterEncrypt(request, subjo);
	}
	
	
	@ResponseBody
	@RequestMapping("/qryProductAgentList")
	public Map<String, Object> qryProductAgentList(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("barId", param.get("barId"));
		qryParam.put("productId", param.get("productId"));
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("barId", 1);
//		qryParam.put("productId",10);
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf("10"));
//		JSONObject subjo = new JSONObject();
		Map<String, Object> retData = moneyBarService.qryProductAgentList(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("nodeList", retData.get("nodeList"));
		int count = 10;
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
	}
	
	@ResponseBody
	@RequestMapping("qryAgentProductByIds")
	public Map<String, Object> qryAgentProductByUserIdAndProductId(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		Map<String, Object> retData = moneyBarService.qryAgentProductByIds(param);
		JSONObject subjo = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
		subjo.put("agentProduct", retData.get("agentProduct"));
		return parameterEncrypt(request, subjo);
	}
	
	@ResponseBody
	@RequestMapping("/qryProduct1LevelAgentList")
	public Map<String, Object> qryProduct1LevelAgentList(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("barId", param.get("barId"));
		qryParam.put("productId", param.get("productId"));
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("barId", 1);
//		qryParam.put("productId",10);
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf("10"));
//		JSONObject subjo = new JSONObject();
		Map<String, Object> retData = moneyBarService.qryProduct1LevelAgentList(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("nodeList", retData.get("nodeList"));
		int count = 10;
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
	}

    /**
     * 审批代理人
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/auditAgent")
    public Map<String, Object> auditAgent(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		//用户编码
		param.put("auditUserId", request.getAttribute("userId"));
		int count = moneyBarService.auditAgent(param);
		if (count == 1) {
			subjo = new JSONObject();
			subjo.put("result", "00");
	    	subjo.put("message", "审核代理人成功");
		} else {
			subjo = new JSONObject();
	    	subjo.put("result", "01");
	    	subjo.put("message", "审核代理人失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 首页钱吧列表接口
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/qryHomeMoneyBarList")
    public Map<String, Object> qryHomeMoneyBarList(HttpServletRequest request) throws ServiceException {
		List<Map<String, Object>>  moneyBarList = moneyBarService.qryHomeMoneyBarList();
		JSONObject subjo  = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "查询成功");
    	subjo.put("moneyBarList", moneyBarList);
		return parameterEncrypt(request, subjo);
    }
}
